﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace AIthin.Model
{
    class Squash : Reality
    {
        /// <summary>
        /// "Schläger" als Rektangle zu beschreiben
        /// </summary>
        public static Rectangle p;
        /// <summary>
        /// "Ball" der springt rum
        /// </summary>
        public static Ball b = new Ball();
        /// <summary>
        /// "Zimmer" wo Ball springt
        /// </summary>
        public Room room = new Room();
        /// <summary>
        /// Konstruktor für Reality
        /// </summary>
        public Squash(int D) : base (D)
        {
            // Schläger
            p = new Rectangle(32, room.Y + room.H - 4, 10, 5);
        }
        /// <summary>
        /// Zeichnet alle Elemente.
        /// </summary>
        /// <param name="g">GDI+ Zeichnungsoberfläche</param>
        public void Draw(Graphics g)
        {

            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            g.FillRectangle(Brushes.White, room.X, room.Y, room.W, room.H);

            g.FillEllipse(Brushes.Black, b.X, b.Y, b.Size, b.Size);
            g.DrawLine(Pens.Black, room.X, room.H + room.Y, room.X, room.Y);
            g.DrawLine(Pens.Black, room.X, room.Y, room.X + room.W, room.Y);
            g.DrawLine(Pens.Black, room.X + room.W, room.Y, room.X + room.W, room.H + room.Y);

            //Output Reaktion wenn ball geht nach links ein Feld wenn nach rechts anderen feld
            //g.FillRectangle(Brushes.White, room.X + 64, room.Y, room.W, room.H);
            //if (b.Vx < 0)
            //    g.FillRectangle(Brushes.Black, 10 + 64, 10, 20, 10);
            //else
            //    g.FillRectangle(Brushes.Black, 40 + 64, 10, 20, 10);
            // Schlaeger
      //      g.FillRectangle(Brushes.Black, p);

        }
        /// <summary>
        /// Aufnimmt für Schläger die Bewegungen von dem Maus
        /// </summary>
        /// <param name="e"> Mouse Even Arguments</param>
        public void Influense(System.Windows.Forms.MouseEventArgs e)
        {
            if (p.X < 0)
            {
                p.X = 0;
            }
            else
            {
                p.X = e.X;
            }
        }
        /// <summary>
        /// Schießt Ball von unten
        /// </summary>
        public void ShootBall()
        {
            b.X = base.RandomValue.Next(room.X + 2, room.W + room.X - 6);
            b.Y = room.H;
            b.Vx = base.RandomValue.Next(-5, 5);
            b.Vy = base.RandomValue.Next(1, 5);
        }
        /// <summary>
        /// Modelliert absprung von den Wänden des Zimmer
        /// </summary>
        public void Moving()
        {
            if (b.X < (room.X + room.W - b.Size) & b.X > room.X)
            {
                b.X += b.Vx;
            }
            else
            {
                b.Vx = -b.Vx;
                b.X += b.Vx;
            }
            if (b.Y > room.Y)
            {
                b.Y -= b.Vy;
            }
            else
            {
                b.Vy = -b.Vy;
                b.Y -= b.Vy;
            }
            if (b.Y > (room.H + room.Y))
            {
                b.Y = room.H + room.Y + 20;
                b.X = room.X + 20;
                this.ShootBall();
            }

        }
    }
}
